<template>
	<view :data-theme="themeStyle">
	<mescroll-uni ref="mescroll" @getData="getData">
		<block slot="list">
			<view class="nc-info-list-content" v-if="dataList.length>0">
				<view class="list-item" v-for="(item, index) in dataList" :key="index">
					<view class="item-top" @click="setDefault(item.id)">
						<view>
							<text class="top-title">{{ item.realname }}</text>
							<text class="top-num">{{ item.mobile }}</text>
						</view>
						<text v-if="item.withdraw_type == 'alipay'">提现账号：{{ item.bank_account }}</text>
						<text v-if="item.withdraw_type == 'bank'">银行名称 ：{{ item.branch_bank_name }}</text>
					</view>
					<view class="item-bottom">
						<text>账号类型 ：{{ item.withdraw_type_name }}</text>
						<view>
							<text @click.stop="editAccount('edit', item.id)">修改</text>
							<text v-if="item.is_default != 1" @click.stop="deleteAccount(item.id)">删除</text>
						</view>
					</view>
					<view v-if="item.is_default == 1" class="ns-bg-color item-mr">默认</view>
				</view>
				<button class="add-account" type="primary" @click="editAccount('add')">{{ $lang('newAddAccount') }}</button>
			</view>
			<view v-else class="cart-empty">
				<ns-empty :text="$lang('emptyText')" :isIndex="false" :fixed="!1" class="zw"></ns-empty>
				<button class="add-account" type="primary" @click="editAccount('add')">{{ $lang('newAddAccount') }}</button>
			</view>
			<loading-cover ref="loadingCover"></loading-cover>
		</block>
	</mescroll-uni>
	<ns-show-toast></ns-show-toast>
	</view>
</template>

<script>
import globalConfig from '@/common/js/golbalConfig.js'
import nsShowToast from '@/components/ns-show-toast/ns-show-toast.vue'
export default {
	data() {
		return {
			dataList: [], //账号列表
			back: '', // 返回页
			redirect: 'redirectTo',// 跳转方式
		};
	},
	components: {
		nsShowToast
	},
	mixins: [globalConfig],
	onLoad(option) {
		if (option.back) this.back = option.back;
		if (option.redirect) this.redirect = option.redirect;
	},
	onShow() {
		// 刷新多语言
		this.$langConfig.refresh();
		if (this.$refs.mescroll) this.$refs.mescroll.refresh();
	},
	methods: {
		// 编辑提现账户信息
		editAccount(type, id) {
			let data = {};
			if (type == 'edit') data.id = id;
			this.$util.redirectTo('/otherpages/member/account_edit/account_edit', data);
		},
		deleteAccount(id) {
			uni.showModal({
				title: '操作提示',
				content: '确定要删除该账户吗？',
				success: res => {
					if (res.confirm) {
						this.$api.sendRequest({
							url: '/api/memberbankaccount/delete',
							data: {id:id},
							success: result => {
								if (result.code == 0) {
									this.$util.showToast({ title: '删除成功' });
									this.$refs.mescroll.refresh();
								} else {
									this.$util.showToast({ title: '删除失败' });
								}
							}
						});
					}
				}
			});
		},
		setDefault(id) {
			this.$api.sendRequest({
				url: '/api/memberbankaccount/setdefault',
				data: { id },
				success: res => {
					if (res.data >= 0) {
						if (this.back != '') {
							this.$util.redirectTo(this.back, {}, this.redirect);
						} else {
							this.$refs.mescroll.refresh();
						}
					} else {
						this.$util.showToast({ title: res.message });
					}
				}
			});
		},
		getData(mescroll) {
			this.$api.sendRequest({
				url: '/api/memberbankaccount/page',
				data: {
					page_size: mescroll.size,
					page: mescroll.num
				},
				success: res => {
					let newArr = [];
					let msg = res.message;
					if (res.code == 0 && res.data) {
						newArr = res.data.list;
					} else {
						this.$util.showToast({ title: msg });
					}
					mescroll.endSuccess(newArr.length);
					//设置列表数据
					if (mescroll.num == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.dataList = this.dataList.concat(newArr); //追加新数据
					
					let withdrawType = {
						'bank': '银行',
						'alipay': '支付宝',
						'wechatpay': '微信'
					};
					
					this.dataList.forEach(item=>{
						// item.withdraw_type_name = withdrawType[item.withdraw_type] ?? ''
						item.withdraw_type_name = withdrawType[item.withdraw_type] ? withdrawType[item.withdraw_type] : ''
					})
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					mescroll.endErr();
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		}
	}
};
</script>

<style lang="scss">
	/deep/ .fixed{position: relative;top:0}
	/deep/ .empty{margin-top: 0 !important;}
	.cart-empty{position:relative;top: 50%;padding-top: 104px !important;}
	.add-account{margin-top: 5vh;}
	.zw {
		margin-top: 250rpx;
	}
	.list-item {
		width: 702rpx;
		margin: 0 auto;
		padding: 37rpx 24rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		background-color: #fff;
		margin-bottom: 18rpx;
		border-radius: 10rpx;
		overflow: hidden;
		position: relative;
		&:first-child {
			margin-top: 18rpx;
		}
		.item-mr {
			font-size: $ns-font-size-x-sm;
			color: #fff;
			height: 150rpx;
			width: 150rpx;
			display: flex;
			align-items: flex-end;
			justify-content: center;
			position: absolute;
			right: -90rpx;
			top: -90rpx;
			transform: rotate(45deg);
		}
		.item-top {
			border-bottom: 1px solid #f1f1f1;
			padding-bottom: 26rpx;
			display: flex;
			flex-direction: column;
			view {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 33rpx;
				.top-title {
					color: #000;
					font-size: $ns-font-size-lg;
				}
				.top-num {
					color: #000;
					font-size: $ns-font-size-base;
				}
			}
			text {
				color: #535353;
				font-size: $ns-font-size-base;
			}
		}
		.item-bottom {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 26rpx;
			text {
				font-size: $ns-font-size-base;
				color: #535353;
			}
			view {
				text {
					font-size: $ns-font-size-base;
					color: #A9A9A9;
					margin-left: 50rpx;
				}
			}
		}
	}
	
	
	
	
	
	
	
	
	
	
</style>
<style>
	/deep/ .mescroll-upwarp{
		padding-bottom: 150rpx;
	}
</style>
